import requests

if __name__ == '__main__':
    # 假设这是一个图片的 URL
    post_url = r"https://tieba.baidu.com/f?&kw=%E5%90%8A%E5%9B%BE&ie=utf-8&pn=0"  

    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
    }

    response = requests.get(url=post_url, headers=headers)

    # 检查请求是否成功
    if response.status_code == 200:
        filename = "diaotu.html"
        # 以二进制写入模式打开文件
        with open(filename, 'wb') as file:
            # 将图片数据写入文件
            file.write(response.content)
        print(f"网页已保存为 {filename}")
    else:
        print(f"请求失败，状态码: {response.status_code}")
